from langchain_core.messages import HumanMessage, SystemMessage
from langchain_core.prompts import ChatPromptTemplate
from langchain.chat_models import init_chat_model

# --------------- 一般使用 ------------------
messages = [
    SystemMessage(content="Translate the following from English into Chinese"),
    HumanMessage(content="hi!"),
]

model3 = init_chat_model("gpt-4o-mini", model_provider="openai")
res = model3.invoke(messages)
print(res)

# ------------- 提示词模板 -------------------
system_template = "Translate the following from English into {language}"

prompt_template = ChatPromptTemplate.from_messages(
    [("system", system_template), ("user", "{text}")]
)

prompt = prompt_template.invoke({"language": "Italian", "text": "Hi!"})
print(prompt)
response = model3.invoke(prompt)
print(response.content)


